package net.yla.smartbus.core.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.subject.Subject;

import java.util.List;

/**
 * @author: KongXianDe
 * @date: 2018/12/4 11:49
 */
public class ShiroUtils {

    /**
     * 加密算法
     */
//    public final static String hashAlgorithmName = "SHA-256";
    public final static String hashAlgorithmName = "MD5";
    /**
     * 循环次数
     */
    public final static int hashIterations = 16;

    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }

    // 密码加密
    public static String md5(String password, String salt) {
        return new SimpleHash(hashAlgorithmName, password, salt, hashIterations).toString();
    }

    //散列码加密算法
    public static String md5HashCode(List<String> list) {
        StringBuffer sb = new StringBuffer();
        for (String str : list) {
            sb.append(new SimpleHash(hashAlgorithmName,str, hashIterations).toString());
        }
        return sb.toString();
    }

    /**
     * 登出
     */
    public static void logout() {
        SecurityUtils.getSubject().logout();
    }

}
